<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>junglego: main.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">junglego
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">main.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="main_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00009"></a>00009 <span class="preprocessor">#if defined(_WIN32) || defined(_WIN64)</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#include &lt;windows.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#endif</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span>
<a name="l00013"></a>00013 <span class="comment">//CLASS INCLUDES</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &quot;<a class="code" href="gl_helper_8hpp.html">glHelper.hpp</a>&quot;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="types_8hpp.html">types.hpp</a>&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="world_8hpp.html">world.hpp</a>&quot;</span>
<a name="l00018"></a>00018 <span class="keyword">using namespace </span>std;
<a name="l00019"></a>00019 
<a name="l00020"></a><a class="code" href="main_8cpp.html#a710b66d6ee2c4396c4fad5f92c8170af">00020</a> <span class="keyword">const</span> <a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> <a class="code" href="main_8cpp.html#a710b66d6ee2c4396c4fad5f92c8170af">CR_NUM</a> = 200;
<a name="l00021"></a><a class="code" href="main_8cpp.html#a2bbd088aa4ad488a7f0eb7c8992a606d">00021</a> <span class="keyword">const</span> <a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> <a class="code" href="main_8cpp.html#a2bbd088aa4ad488a7f0eb7c8992a606d">XSize</a> = 1024;
<a name="l00022"></a><a class="code" href="main_8cpp.html#a5e4c6461f5ff5ff0b90db0aaea87f99e">00022</a> <span class="keyword">const</span> <a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> <a class="code" href="main_8cpp.html#a5e4c6461f5ff5ff0b90db0aaea87f99e">YSize</a> = 550;
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="comment">//Global</span>
<a name="l00025"></a><a class="code" href="main_8cpp.html#ab8ef1bf8a70cc07c6d55823c390a7e76">00025</a> <span class="keywordtype">float</span> <a class="code" href="gl_helper_8cpp.html#ab8ef1bf8a70cc07c6d55823c390a7e76">angle</a>=0.0f;
<a name="l00026"></a><a class="code" href="main_8cpp.html#a5e2ce8a619b5c209e179303df57c5028">00026</a> <a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> <a class="code" href="main_8cpp.html#a5e2ce8a619b5c209e179303df57c5028">gFramesPerSecond</a>=60;
<a name="l00027"></a><a class="code" href="main_8cpp.html#a51cd2dda508b1fc59d6ca73ee7f8b8c9">00027</a> clock_t <a class="code" href="main_8cpp.html#a51cd2dda508b1fc59d6ca73ee7f8b8c9">gClock</a>;
<a name="l00028"></a><a class="code" href="main_8cpp.html#acf57cf6778fa99df637c1826b51026fe">00028</a> <span class="keywordtype">int</span> <a class="code" href="main_8cpp.html#acf57cf6778fa99df637c1826b51026fe">doPause</a> = -1;
<a name="l00029"></a><a class="code" href="main_8cpp.html#a8524210767eebeb4926a5f30f8bbbb68">00029</a> <a class="code" href="class_world.html">World</a> <a class="code" href="main_8cpp.html#a8524210767eebeb4926a5f30f8bbbb68">world</a>;
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="main_8cpp.html#a6819355374dd277347abd7c4235f0cd7">00031</a> <span class="keywordtype">void</span> <a class="code" href="main_8cpp.html#a6819355374dd277347abd7c4235f0cd7">reshape</a> (<span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height) {
<a name="l00032"></a>00032     glViewport(0, 0, (GLsizei)width, (GLsizei)height); <span class="comment">// Set our viewport to the size of our window</span>
<a name="l00033"></a>00033     glMatrixMode(GL_PROJECTION); <span class="comment">// Switch to the projection matrix so that we can manipulate how our scene is viewed</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035     <span class="comment">// Reset the projection matrix to the identity matrix</span>
<a name="l00036"></a>00036     <span class="comment">// so that we don&#39;t paintget any artifacts (cleaning up)</span>
<a name="l00037"></a>00037     glLoadIdentity();
<a name="l00038"></a>00038 
<a name="l00039"></a>00039     <span class="comment">// Disable Z check</span>
<a name="l00040"></a>00040     glDisable(GL_DEPTH_TEST);
<a name="l00041"></a>00041 
<a name="l00042"></a>00042     <span class="comment">// Set the Field of view angle (in degrees),</span>
<a name="l00043"></a>00043     <span class="comment">// the aspect ratio of our window, and the new and far planes</span>
<a name="l00044"></a>00044     <span class="comment">//gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);</span>
<a name="l00045"></a>00045     glOrtho(0, width, height, 0, 0, 1);
<a name="l00046"></a>00046 
<a name="l00047"></a>00047     <span class="comment">// Switch back to the model view matrix, so that we can start drawing shapes correctly</span>
<a name="l00048"></a>00048     glMatrixMode(GL_MODELVIEW);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 
<a name="l00051"></a><a class="code" href="main_8cpp.html#a2a21db8c995e9afe9718d9cccf050e24">00051</a> <span class="keywordtype">void</span> <a class="code" href="main_8cpp.html#a2a21db8c995e9afe9718d9cccf050e24">keyboard_check</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> key, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) {
<a name="l00052"></a>00052     <span class="keywordflow">switch</span>(key) {
<a name="l00053"></a>00053     <span class="keywordflow">case</span> <span class="charliteral">&#39;q&#39;</span>:
<a name="l00054"></a>00054     <span class="keywordflow">case</span> <span class="charliteral">&#39;Q&#39;</span>:
<a name="l00055"></a>00055         <span class="comment">//quit application</span>
<a name="l00056"></a>00056         cout&lt;&lt;<span class="stringliteral">&quot;Quitting JungleGo&quot;</span>&lt;&lt;endl;
<a name="l00057"></a>00057         exit (0);   <span class="comment">//todo: more graceful exit</span>
<a name="l00058"></a>00058         <span class="keywordflow">break</span>;
<a name="l00059"></a>00059     <span class="keywordflow">case</span> <span class="charliteral">&#39;s&#39;</span>:
<a name="l00060"></a>00060     <span class="keywordflow">case</span> <span class="charliteral">&#39;S&#39;</span>:
<a name="l00061"></a>00061         <span class="comment">//pause opengl</span>
<a name="l00062"></a>00062         <span class="keywordflow">if</span>(<a class="code" href="main_8cpp.html#acf57cf6778fa99df637c1826b51026fe">doPause</a>!=1)
<a name="l00063"></a>00063             cout&lt;&lt;<span class="stringliteral">&quot;JungleGo Paused&quot;</span>&lt;&lt;endl;
<a name="l00064"></a>00064         <span class="keywordflow">else</span>
<a name="l00065"></a>00065             cout&lt;&lt;<span class="stringliteral">&quot;JungleGo Unpaused&quot;</span>&lt;&lt;endl;
<a name="l00066"></a>00066         <a class="code" href="main_8cpp.html#acf57cf6778fa99df637c1826b51026fe">doPause</a>*=-1;
<a name="l00067"></a>00067         <span class="keywordflow">break</span>;
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069     glutPostRedisplay();
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="main_8cpp.html#a36d31d6ec7094a3a659a6a0381c66a60">00072</a> <span class="keywordtype">void</span> <a class="code" href="main_8cpp.html#a36d31d6ec7094a3a659a6a0381c66a60">mouse_check</a>(<span class="keywordtype">int</span> button, <span class="keywordtype">int</span> state, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) {
<a name="l00073"></a>00073     <span class="keywordflow">switch</span>(button) {
<a name="l00074"></a>00074     <span class="keywordflow">case</span> GLUT_LEFT_BUTTON:
<a name="l00075"></a>00075         <span class="keywordflow">if</span>(button==GLUT_UP) {
<a name="l00076"></a>00076 
<a name="l00077"></a>00077         } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(button==GLUT_DOWN) {
<a name="l00078"></a>00078 
<a name="l00079"></a>00079         } <span class="keywordflow">else</span> {
<a name="l00080"></a>00080 
<a name="l00081"></a>00081         }
<a name="l00082"></a>00082         <span class="keywordflow">break</span>;
<a name="l00083"></a>00083     <span class="keywordflow">case</span> GLUT_RIGHT_BUTTON:
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         <span class="keywordflow">break</span>;
<a name="l00086"></a>00086     <span class="keywordflow">case</span> GLUT_MIDDLE_BUTTON:
<a name="l00087"></a>00087 
<a name="l00088"></a>00088         <span class="keywordflow">break</span>;
<a name="l00089"></a>00089     }
<a name="l00090"></a>00090     glutPostRedisplay();
<a name="l00091"></a>00091 }
<a name="l00092"></a><a class="code" href="main_8cpp.html#a1e5b20fed15743656bb6d2e6a6ea6269">00092</a> <span class="keywordtype">void</span> <a class="code" href="main_8cpp.html#a1e5b20fed15743656bb6d2e6a6ea6269">display</a>() {
<a name="l00093"></a>00093     <a class="code" href="main_8cpp.html#a8524210767eebeb4926a5f30f8bbbb68">world</a>.<a class="code" href="class_world.html#a7fa844c028cf185a5f90359cceeabf7c">paint</a>();
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="main_8cpp.html#a3e73164d603e05e94b8eedeb557a3245">00096</a> <span class="keywordtype">void</span> <a class="code" href="main_8cpp.html#a3e73164d603e05e94b8eedeb557a3245">animate</a>() {
<a name="l00097"></a>00097 <span class="preprocessor">#if defined(_WIN32) || defined(_WIN64)</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span>    Sleep(1000/<a class="code" href="main_8cpp.html#a5e2ce8a619b5c209e179303df57c5028">gFramesPerSecond</a>);
<a name="l00099"></a>00099 <span class="preprocessor">#else</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span>    usleep(1000000/<a class="code" href="main_8cpp.html#a5e2ce8a619b5c209e179303df57c5028">gFramesPerSecond</a>);
<a name="l00101"></a>00101 <span class="preprocessor">#endif</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span>    <span class="keywordflow">if</span>(<a class="code" href="main_8cpp.html#acf57cf6778fa99df637c1826b51026fe">doPause</a>!=1) {
<a name="l00103"></a>00103         <a class="code" href="main_8cpp.html#a8524210767eebeb4926a5f30f8bbbb68">world</a>.<a class="code" href="class_world.html#aac8c1fde63c06577ffc648aaefdb37f0">update</a>();
<a name="l00104"></a>00104         glutPostRedisplay();
<a name="l00105"></a>00105     }
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107 
<a name="l00108"></a><a class="code" href="main_8cpp.html#a0be26f297e969c1bec3fabc753fbcee8">00108</a> <span class="keywordtype">void</span> <a class="code" href="gl_helper_8hpp.html#a0be26f297e969c1bec3fabc753fbcee8">initCore</a>() {
<a name="l00109"></a>00109     <a class="code" href="main_8cpp.html#a8524210767eebeb4926a5f30f8bbbb68">world</a>.<a class="code" href="class_world.html#a695e14e5574f9bbdf58c8f39538b11d3">init</a>(<a class="code" href="main_8cpp.html#a710b66d6ee2c4396c4fad5f92c8170af">CR_NUM</a>, 10, <a class="code" href="main_8cpp.html#a2bbd088aa4ad488a7f0eb7c8992a606d">XSize</a>, <a class="code" href="main_8cpp.html#a5e4c6461f5ff5ff0b90db0aaea87f99e">YSize</a>);
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="main_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">00112</a> <span class="keywordtype">int</span> <a class="code" href="main_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) {
<a name="l00113"></a>00113     <a class="code" href="main_8cpp.html#a51cd2dda508b1fc59d6ca73ee7f8b8c9">gClock</a> = clock();
<a name="l00114"></a>00114     glutInit(&amp;argc, argv); <span class="comment">// Initialize GLUT</span>
<a name="l00115"></a>00115     glutInitDisplayMode (GLUT_DOUBLE); <span class="comment">// Set up a basic display double buffer</span>
<a name="l00116"></a>00116     glutInitWindowSize (<a class="code" href="main_8cpp.html#a2bbd088aa4ad488a7f0eb7c8992a606d">XSize</a>, <a class="code" href="main_8cpp.html#a5e4c6461f5ff5ff0b90db0aaea87f99e">YSize</a>); <span class="comment">// Set the width and height of the window</span>
<a name="l00117"></a>00117     glutInitWindowPosition (0, 0); <span class="comment">// Set the position of the window</span>
<a name="l00118"></a>00118     glutCreateWindow (<span class="stringliteral">&quot;Welcome to Jungle Go&quot;</span>); <span class="comment">// Set the title for the window</span>
<a name="l00119"></a>00119 
<a name="l00121"></a>00121     <a class="code" href="gl_helper_8hpp.html#a0be26f297e969c1bec3fabc753fbcee8">initCore</a>();
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     glutDisplayFunc(<a class="code" href="main_8cpp.html#a1e5b20fed15743656bb6d2e6a6ea6269">display</a>); <span class="comment">// Tell GLUT to use the method &quot;display&quot; for rendering</span>
<a name="l00124"></a>00124     glutReshapeFunc(<a class="code" href="main_8cpp.html#a6819355374dd277347abd7c4235f0cd7">reshape</a>); <span class="comment">// Tell GLUT to use the method &quot;reshape&quot; for rendering</span>
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     glutIdleFunc(<a class="code" href="main_8cpp.html#a3e73164d603e05e94b8eedeb557a3245">animate</a>); <span class="comment">// Tell GLUT to run this anytime he can</span>
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     glutKeyboardFunc(<a class="code" href="main_8cpp.html#a2a21db8c995e9afe9718d9cccf050e24">keyboard_check</a>);   <span class="comment">// Keyboard</span>
<a name="l00129"></a>00129     glutMouseFunc(<a class="code" href="main_8cpp.html#a36d31d6ec7094a3a659a6a0381c66a60">mouse_check</a>);         <span class="comment">// Mouse</span>
<a name="l00130"></a>00130 
<a name="l00131"></a>00131     glutMainLoop(); <span class="comment">// Enter GLUT&#39;s main loop</span>
<a name="l00132"></a>00132     <span class="keywordflow">return</span> 1;
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 20 2012 21:57:14 for junglego by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
